import javax.swing.table.AbstractTableModel;

public class ProductTableModel extends AbstractTableModel {
	private static final long serialVersionUID = -9062486697492259853L;
	String[] columnNames = { "Code", "Naam", "Prijs", "Categorie" };
	private Object[][] data;

	public ProductTableModel(Object[][] data) {
		this.data = data;
	}
	@Override
	public int getColumnCount() {
		return columnNames.length;
	}

	public String getColumnName(int col) {
		return columnNames[col];
	}

	@Override
	public int getRowCount() {
		return data.length;
	}

	@Override
	public Object getValueAt(int row, int col) {
		return data[row][col];
	}

	public void setValueAt(Object value, int row, int col) {
		data[row][col] = value;
		fireTableCellUpdated(row, col);
		
	}

	public int insertAndClear(Object[][] content) {
		int oud = data.length;
		int nieuw = content.length;
		data = content;
		for (int i = 0; i < data.length; i++) {
			for (int j = 0; j < 4; j++) {
				setValueAt(data[i][j], i, j);
			}
		}
		if(oud>nieuw)this.fireTableRowsDeleted(oud, nieuw);
		else if(oud<nieuw)this.fireTableRowsInserted(oud, nieuw);
		return data.length;
	}
	
		

}
